package com.licerlee.controller;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.licerlee.entity.User;

/**
 * 
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/users")
public class UserController {

	private Logger logger = LoggerFactory.getLogger(getClass());

	
	@GetMapping
	public List<User> getUser(){
		logger.info("获取用户列表");
		User u = new User("1", "liwenchao", "123");
		User u1 = new User("2", "licerlee", "456");
		List<User> users = new ArrayList<>();
		users.add(u);
		users.add(u1);
		return users;
	}
	
	
	@PostMapping
	public User postUser(@RequestBody User user){
		logger.info("User %s saved", user.toString());
		return user;
	}
	
	
	@GetMapping("/{id}")
	public User byId(@PathVariable String id){
		User user = new User();
		user.setId(id);
		return user;
		
	}
	
	
}
